#include<bits/stdc++.h>
using namespace std;
const int NN=2e5+4,MM=304,KK=MM*MM,P=998244353;
char be; 
int n,v[NN],c[NN],x[NN];
long long f[MM][KK];
char ed;
void solve1()
{
	for(int i=n;i;i--)
	{
		if(i<n)
			for(int j=0;j*x[i]<KK&&j+c[i+1]<KK;j++)
				f[i][j*x[i]]=f[i+1][j+c[i+1]];
		for(int j=1;j<KK;j++)
			f[i][j]=max(f[i][j],f[i][j-1]+v[i]);
	}
	printf("%lld",f[1][c[1]]%P);
}
void solve2()
{
	int ans=0,maxx=0;
	for(int i=n;i>=1;i--)
	{
		maxx=max(maxx,v[i]);
		ans=(ans+1ll*c[i]*maxx%P)%P;
	}
	printf("%d",ans);
}
void solve3()
{
	for(int i=1;i<n;i++)
		if(1ll*v[i]*(c[i]/x[i]*x[i])<1ll*v[i+1]*(c[i]/x[i]))
		{
			c[i+1]+=c[i]/x[i];
			c[i]%=x[i];
		}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+1ll*c[i]*v[i]%P)%P;
	printf("%d",ans);
}
int main()
{
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout);
	bool chk1=true,chk5=true,chk4=true;
	scanf("%d",&n);
	if(n>300)
		chk1=false;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&v[i]);
		if(v[i]>300)
			chk1=false;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&c[i]);
		if(c[i]>300)
			chk1=false;
	}
	for(int i=1;i<n;i++)
	{
		scanf("%d",&x[i]);
		if(x[i]!=1)
			chk5=false;
		if(x[i]!=1000000000)
			chk4=false;
	}
	if(chk1)
		solve1();
	else if(chk5)
		solve2();
	else
		solve3();
	return 0;
}
